package com.ray.exercise.security.credentials;

import com.ray.exercise.utils.DigestsUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;

/**
 * @author reny
 * created at 2024/6/19 14:38
 **/
public class DigestCredentialsMatcher implements CredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken loginInfo = (UsernamePasswordToken) token;
        String passwordHash = DigestsUtils.md5(loginInfo.getPassword(), loginInfo.getUsername());
        return passwordHash.equals(info.getCredentials().toString());
    }
}
